package com.liwy3.consume;

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.annotation.TopicPartition;
import org.springframework.stereotype.Component;

/**
 * Copyright © 元气森林（北京）食品科技集团有限公司. All rights reserved.
 *
 * @Description:
 * @author: Crazy4J
 * @date: 2022年04月21日 14:52
 * @version: V1.0
 */
@Component
@Slf4j
public class BuyConsumer {

    /**
     * topicPartitions = {
     *
     * @param record
     * @TopicPartition(topic = "topic1",partitions = {"0"}),
     * @TopicPartition(topic = "topic2",partitions = "0",
     * partitionOffsets = @PartitionOffset(partition = "1",initialOffset = "8")
     */
    @KafkaListener(groupId = "order-group-1", topicPartitions = {
            @TopicPartition(topic = "buy_topic", partitions = {"0"})})
    public void orderListener(ConsumerRecord<String, String> record) throws InterruptedException {
        Thread.sleep(11L);
        log.info("buy-group-1消费buy_topic, partition：{},offset:{},消息内容：{}",
                record.partition(), record.offset(), record.value());
    }

//    @KafkaListener(groupId = "pay-group-1", topics = "pay_topic")
//    public void payListener(ConsumerRecord<String, String> record) {
//        log.info("pay-group-1消费pay_topic, partition：{},offset:{},消息内容：{}",
//                record.partition(), record.offset(), record.value());
//    }


}
